import pandas as pd
import numpy as np

# 生成随机数据
num_rows = 1000 #excel表的行数
num_cols = 10   #excel表的列数
num_max = 99    #生成数据的最大值 - num_min
num_min = 1     #生成数据的最小值
data = np.random.random(size=(num_rows, num_cols)) * num_max + num_min

# 自定义行名
custom_index = [f"Row{i}" for i in range(1, num_rows + 1)]

# 自定义列名
custom_columns = [f"Column{i}" for i in range(1, num_cols + 1)]


#自定义小数的位数
# decimal_places = 3
# data = np.round(data, decimals=decimal_places)

# 将数据转换为字符串格式化小数位数
data = np.array([["{:.2f}".format(num) for num in row] for row in data])

# 创建DataFrame
df = pd.DataFrame(data, index=custom_index,columns=custom_columns)

# 写入Excel文件,index = True,行头才会显示出来
output_file = "random_data.xlsx"
df.to_excel(output_file, index=True)

print(f"Random data written to {output_file}")
